<!--
 * @Author: ChunLai
 * @Date: 2021-12-28 21:13:33
 * @LastEditTime: 2023-08-11 17:08:53
 * @Description: 
 * @FilePath: \0.newInsure\src\views\read\PdfFile.vue
-->
<template>
  <div class="fee-count-pre-module">
    <div class="right-fix-btn" v-if="pdfh5">
      <div class="count-down" v-if="countNum > 0">
        {{ `${countNum}s` }}
      </div>
      <div class="read-back" @click="sureClick" v-else>我已阅读</div>
    </div>

    <div id="demo"></div>
  </div>
</template>

<script>
import { pdfJs } from "@/utils/pdfh5";
export default {
  name: "PdfFile",
  props: ["fileObj"],
  data() {
    return {
      pdfh5: null,
      countNum: 5,
      timeOut: null,
    };
  },
  created() {
    let that = this;
    if (window.Pdfh5) {
      return that.initPdf();
    }
    pdfJs(function (res) {
      that.initPdf();
    });
  },
  methods: {
    initPdf() {
      this.$nextTick(() => {
        this.pdfh5 = new Pdfh5("#demo", {
          pdfurl: this.fileObj.fileUrl,
        });
        let that = this;
        // 监听完成事件
        this.pdfh5.on("complete", function (status, msg, time) {
          that.pdfPageNum = this.totalNum;
          that.countDownEvent();
        });
      });
    },
    countDownEvent() {
      this.timeOut = setInterval(() => {
        this.countNum--;
        if (this.countNum <= 0) {
          clearInterval(this.timeOut);
        }
      }, 1000);
    },
    sureClick() {
      this.$backRouter();
    },
  },
};
</script>

<style lang="less" scoped>
.fee-count-pre-module {
  width: 100%;
  margin-top: 10px;
  height: calc(100vh - 60px);
}

.right-fix-btn {
  position: fixed;
  right: 0;
  left: 0;
  bottom: 0;
  margin: auto;
  z-index: 99;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 50px;
  color: #ffffff;
  box-shadow: rgba(0, 0, 0, 0.3) 0px 2px 12px 0px;
  background-color: #ffffff;

  .count-down {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    line-height: 42px;
    text-align: center;
    font-size: 20px;
    background-color: #fb8c89;
  }

  .read-back {
    width: 60%;
    height: 38px;
    line-height: 38px;
    font-size: 16px;
    letter-spacing: 2px;
    text-align: center;
    background-color: #f52119;
    border-radius: 25px;
  }
}
</style>
